cmake_minimum_required(VERSION 3.12.1)
project(mem_link LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# 设置头文件路径:全局性的，会影响当前目录下所有目标，可能导致不必要的污染
#include_directories(include)

# 收集源文件
set(MEMLINK_SOURCES
    src/tlv_buffer.cpp
    src/tlv_writer.cpp
    src/tlv_reader.cpp
    src/tlv_stream_reader.cpp
    src/tlv_parser.cpp
)

add_library(mem_link SHARED ${MEMLINK_SOURCES})

target_include_directories(mem_link PUBLIC ${CMAKE_SOURCE_DIR}/mem-link/include)

# 示例程序
add_executable(mem_link_example examples/registry_demo.cpp)
target_link_libraries(mem_link_example PRIVATE mem_link)

# 将头文件安装到系统路径 
install(DIRECTORY include/ DESTINATION include)

# 安装动态版本
install(TARGETS mem_link mem_link_example
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib)